package cn.thread;

public class RunnableTest003 implements Runnable{
    private String victory;
    public static void main(String args[]){
        RunnableTest003 r3=new RunnableTest003();
        new Thread(r3,"乌龟").start();
        new Thread(r3,"兔子").start();
    }
    @Override
    public void run() {
     for(int i=0;i<=100;i++){
         System.out.println(Thread.currentThread().getName()+"-->"+i);
         if(Thread.currentThread().getName().equals("兔子") && i%10==0){
             try {
                 new Thread(this).sleep(0);

             } catch (InterruptedException e) {
                 e.printStackTrace();
             }
         }
         boolean flag=play(i);
         if(flag){
             break;
         }
     }
    }
    public boolean play(int i){
        if(victory!=null){
            return true;
        }else{
            if(i==100){
                victory=Thread.currentThread().getName();
                System.out.println("胜利者是"+victory);
                return true;
            }
        }
        return false;
    }


}
